using System;
using System.Collections.Generic;
using System.Text;

using NUnit.Framework;

namespace HabilisDesign.Iota.UnitTests
{
	[TestFixture]
	public class StatusCollectionTests
	{
		string m_GenericStatus = "<status><id>{0}</id><text>Hello</text></status>";
		StatusCollection m_TestCollection;

		[SetUp]
		public void Initialize()
		{
			m_TestCollection = new StatusCollection();
		}

		[Test]
		public void TestMaxSizeIsMaintained()
		{
			int x = 0;
			while ( x++ < 25 )
			{
				m_TestCollection.Add( Status.Parse( string.Format( m_GenericStatus, x ) ) );
			}
			Assert.AreEqual( m_TestCollection.MaxSize, m_TestCollection.Count );
		}

		[Test]
		public void TestDuplicatesAreNotAddedToCollection()
		{
			Status testStatus = Status.Parse( string.Format( m_GenericStatus, 123456 ) );
			int x = 0;
			while ( x++ < 3 )
			{
				m_TestCollection.Add( testStatus );
			}
			Assert.AreEqual( 1, m_TestCollection.Count );
		}

		[Test]
		public void TestAddPutsItemAtBottom()
		{
			Status testStatus1 = Status.Parse( string.Format( m_GenericStatus, 123456 ) );
			Status testStatus2 = Status.Parse( string.Format( m_GenericStatus, 456789 ) );
			m_TestCollection.Add( testStatus1 );
			m_TestCollection.Add( testStatus2 );
			Assert.AreSame( testStatus2, m_TestCollection[m_TestCollection.Count - 1] );
		}

		[Test]
		public void TestInsertPutsItemAtTop()
		{
			Status testStatus1 = Status.Parse( string.Format( m_GenericStatus, 123456 ) );
			Status testStatus2 = Status.Parse( string.Format( m_GenericStatus, 456789 ) );
			m_TestCollection.Add( testStatus1 );
			m_TestCollection.Add( testStatus2 );
			Assert.AreSame( testStatus1, m_TestCollection[0] );
		}

	} // end class

} // end namespace
